package com.zyw.zhuangdian.dao.impl;

import com.zyw.zhuangdian.dao.BaseDao;
import com.zyw.zhuangdian.dao.ConstantDao;
import com.zyw.zhuangdian.exceptions.MyDaoException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Repository
@Transactional
public class ConstantDaoImpl extends BaseDao implements ConstantDao {
    @Override
    public void addConstant(Map in) {
        int i = sqlTemplate.insert("ConstantDaoImpl.addConstant",in);
        if (i<1){
            throw new MyDaoException("插入常量记录失败");
        }
    }

    @Override
    public void updateConstant(Map in) {
        int i = sqlTemplate.update("ConstantDaoImpl.updateConstant",in);
        if (i<1){
            throw new MyDaoException("更新常量记录失败");
        }
    }

    @Override
    public List<Map> listConstant(Map in) {
        List<Map> list = sqlTemplate.selectList("ConstantDaoImpl.listConstants",in);
        return list;
    }

    @Override
    public int listConstantsCount(Map in) {
        List<Map> list = sqlTemplate.selectList("ConstantDaoImpl.listConstantsCount",in);
        if (list.size() < 1){
            return 0;
        }
        return Integer.parseInt(list.get(0).get("count").toString());
    }
}
